<?php 
	include 'Base.class.php';
	class Binary{
		/**
		 * 一参为数组,二参为目标数字
		 */
		public function binSearch($arr,$findNum,$low=0,$top=0){
			//count别名而已
			if (empty($top)) {
				$top = sizeof($arr);				
			}

			$mid = floor(($low+$top)/2);

			if ($arr["$mid"] == $findNum) {
				return $mid;
			}elseif ($arr["$mid"]<$findNum) {
				//递归分层都要加 return 最后的值才能一层一层return回来
				return $this->binSearch($arr,$findNum,($mid+1),$top);
			}else{
				return $this->binSearch($arr,$findNum,$low,($mid-1));
			}
		} 
	}

	//必须有序
	$arr = array(1,5,11,23,45,66,72,214);
	$bs = new Binary();
	$result = $bs->binSearch($arr,66);
 	var_dump($result);
 ?>